<?php
/**
 * Základní třída modelu.
 */
class Model extends Nette\Object
{
    /** @var Nette\Database\Connection */
    public $database;


    /**
     * @param Nette\Database\Connection $database
     */
    public function __construct(Nette\Database\Connection $database)
    {
        $this->database = $database;
    }
    
    /**
     * Získá tabulku uživatelů.
     * @return Nette\Database\Table\Selection
     */
    public function getUsers()
    {
	return $this->database->table('users');
    }    
    
    /**
     * Získá meno uzivatela na zaklade id.
     * @return Nette\Database\Table\Selection
     */
    public function getUserName($id)
    {
	return $this->database->table('users')->find($id)->fetch();
    }    
    
    /**
     * Vrati TRUE ak je user Premium.
     * @return Nette\Database\Table\Selection
     */
    public function isPremium($id)
    {
	if($this->database->table('users')->find($id)->where(array('premium' => '1'))->count() > 0) {
	    return TRUE;
	} else {
	    return FALSE;
	}
    }     
    
    
    /**
     * Ziska msg tabulku
     * @return Nette\Database\Table\Selection
     */
    public function getMsgs()
    {
	return $this->database->table('_msgs');
    }   
}